home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
bioinformatics.org
/
bioinformatics.org_software.tar
/
www.bioinformatics.org
/
download
/
ecell2
/
ecell220setup.exe
/
{app}
/
standard
/
SRCJ
/
EntrySelector.java
< prev
next >
Wrap
Text File
|
2002-07-10
|
18KB
|
622 lines
/**
* title: EntrySelector class (EntrySelector.java)<p>
* illustration : EntrySelector window class<p>
* Copyright (C) 1996-2001 Keio University <p>
* Copyright (C) 1998-2001 Japan Science and Technology Corporation (JST)<p>
* GNU General Public Licence <p>
* Division: Mitsui Knowledge Industry Co. Ltd. Bioscience division <p>
* Version : $Id: EntrySelector.java,v 1.7 2002/05/13 00:23:04 ota Exp $ <p>
*/
package ecell;
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.*;
import javax.swing.plaf.basic.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.io.*;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.Hashtable;
/**
* EntrySelector window class
* @author XD.Zheng
* @version 1.0
* @since JDK1.2.2
*/
class EntrySelector extends JFrame implements ActionListener
{
JPanel rightPanel = new JPanel(new BorderLayout());
JPanel jp1 = new JPanel();
JPanel jp2 = new JPanel();
JPanel jp3 = new JPanel();
JButton buttonOk = new JButton("Ok");
JButton buttonCancel = new JButton("Cancel");
JRadioButton radioSubstance = new JRadioButton("Substance");
JRadioButton radioReactor = new JRadioButton("Reactor");
Border border1;
JLabel label1= new JLabel("System:");
/**
* Number indicating the called item
*/
int parent = 0;
/**
* Selected item
*/
Object object [] ;
/**
* Tree structure
*/
JTree jTree = new JTree();
/**
* ListModel
*/
DefaultListModel model = new DefaultListModel();
/**
* List
*/
JList jList;
/**
* Full Path
*/
String path = "";
/**
* TreeModel
*/
MyTreeModel treeModel;
/**
* Search for ListModel with System item as a key.
*/
Hashtable listmode = new Hashtable();
/**
* Current TreeNode
*/
String currentStr = null;
/**
* Storing array of window ID
*/
int[] winId =new int[1];
/**
* ClassName
*/
String[] className;
/**
* Selected number of ListItem
*/
int idObject [];
/**
* Parent tracer, required for being called from Tracer
*/
Tracer tracer;
/**
* Number of radioButton 1 Substance 2 Reactor
*/
int radioCode = 1;
/**
* Instance of control panel
*/
MainWindow window ;
/**
* Constructor
* @param parent Target called by the program 0 Tracer 1 SubstanceItem 2 ReactorItem
* @param window Controller Panel
*/
public EntrySelector(int parent,MainWindow window){
this.parent = parent;
this.window = window;
if(parent==0){
radioSubstance.setSelected(true);
radioCode = 1;
}else if(parent == 1){
radioSubstance.setSelected(true);
radioReactor.setEnabled(false);
radioCode = 1;
}else if(parent == 2){
radioReactor.setSelected(true);
radioSubstance.setEnabled(false);
radioCode = 2;
}
try {
jbInit();
}
catch(Exception e) {
window.messageWindow.setErrorMessage( e );
}
}
/**
* Set the window property according to the called item.
* @param parent Target called by the program 0 Tracer 1 SubstanceItem 2 ReactorItem
* @return void
*/
public void setEntrySelector(int parent){
this.parent = parent;
if(parent==0){
radioSubstance.setEnabled(true);
radioSubstance.setEnabled(true);
radioSubstance.setSelected(true);
radioCode = 1;
}else if(parent == 1){
radioSubstance.setEnabled(true);
radioSubstance.setSelected(true);
radioReactor.setEnabled(false);
radioCode = 1;
}else if(parent == 2){
radioReactor.setEnabled(true);
radioReactor.setSelected(true);
radioSubstance.setEnabled(false);
radioCode = 2;
}
if(radioSubstance.isSelected() ) {
radioCode =1;
} else if(radioReactor.isSelected() ) {
radioCode =2;
}
String str="";
if(currentStr != null){
if(radioCode ==1){
str = currentStr +"65536";
}else{
str =currentStr +"65537";
}
}
model.removeAllElements();
if(currentStr!=null)
setListMode(str);
}
/**
* Initialize
* @return void
*/
public void jbInit() /*throws Exception*/ {
this.setTitle("Entry Selector");
this.setSize(512,512);
treeModel= new MyTreeModel(this);
jTree.addTreeSelectionListener( treeSListener );
border1 = BorderFactory.createBevelBorder(BevelBorder.LOWERED,Color.white,Color.white,new Color(134, 134, 134),new Color(93, 93, 93));
String s = null;
try
{
s = window.df.getEntryData();
}
catch( Exception e )
{
window.messageWindow.setErrorMessage( e );
}
jTree.setModel(treeModel.getMyTreeModel2(s) );
JScrollPane jScrollPane = new JScrollPane(jTree);
ButtonGroup buttonGroup = new ButtonGroup();
jList = new JList(model);
jList.setFont(new java.awt.Font("DialogInput", 0, 12));
jList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
jList.addListSelectionListener(listListener);
jp2.setLayout(new FlowLayout(0,0,2));
jp2.add(label1);
jList.setBackground(Color.lightGray);
jList.setBorder(border1);
buttonGroup.add(radioSubstance);
buttonGroup.add(radioReactor);
radioSubstance.addActionListener(actionListener);
radioReactor.addActionListener(actionListener);
jp1.add(radioSubstance);
jp1.add(radioReactor);
rightPanel.add(jp1,"North");
rightPanel.add(new JScrollPane( jList ),"Center");
JSplitPane jSplitPane =
new JSplitPane(
JSplitPane.HORIZONTAL_SPLIT,
jScrollPane,
rightPanel
);
// 2002.6.27
jSplitPane.setDividerLocation( 138 );
jp3.setLayout(new FlowLayout(0,2,2));
jp3.add(buttonOk);
jp3.add(buttonCancel);
buttonOk.addActionListener(this);
buttonCancel.addActionListener(this);
this.getContentPane().add( jp2,BorderLayout.NORTH);
this.getContentPane().add( jSplitPane , BorderLayout.CENTER);
this.getContentPane().add( jp3 , BorderLayout.SOUTH);
}
/**
* The generation of ListMode
* @param string TreeNode character string
* @return void
*/
void setListMode(String strKey){
Vector vr = (Vector)listmode.get(strKey);
if(vr !=null){
int num= vr.size();
winId = new int[num];
className= new String[num];
for(int i=0;i<num;i++){
String str = (String)vr.elementAt(i);
StringTokenizer st = new StringTokenizer(str,"\t");
winId[i] = Integer.parseInt(st.nextToken());
model.addElement(st.nextToken());
className[i]=st.nextToken();
}
}
}
/**
* Set Field of Tracer
* @param tracer Instance of Tracer
* @return void
*/
public void setTracer(Tracer tracer){
this.tracer=tracer;
}
/**
* Override to exit when the window is closed.
* @param e WindowEvent
* @return void
*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
this.setVisible(false);
}
}
/**
*TreeSelectionListener
*/
private TreeSelectionListener treeSListener = new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
TreePath treePath = (TreePath ) e.getPath();
String abc = "";
int count = treePath.getPathCount();
for(int i=0; i<count;i++){
if (i>1) {
abc += "/"+treePath.getPathComponent(i).toString();
}else {
abc += treePath.getPathComponent(i).toString();
}
}
path = abc;
DefaultMutableTreeNode symbol =
(DefaultMutableTreeNode) treePath.getLastPathComponent();
model.removeAllElements();
String str=(String) symbol.getUserObject();
currentStr =str;
if(radioCode==1){
str=str+"65536";
}else{
str=str+"65537";
}
setListMode(str);
}
};
/**
*Inter Class
*/
private ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(radioSubstance.isSelected() ) {
radioCode =1;
} else if(radioReactor.isSelected() ) {
radioCode =2;
}
String str="";
if(currentStr != null){
if(radioCode ==1){
str = currentStr +"65536";
}else{
str =currentStr +"65537";
}
}
model.removeAllElements();
if(currentStr!=null)
setListMode(str);
}
};
/**
* ListSelectionListener
*/
private ListSelectionListener listListener = new ListSelectionListener(){
public void valueChanged(ListSelectionEvent evt){
object = (Object []) jList.getSelectedValues();
idObject =jList.getSelectedIndices();
}
};
/**
* ActionPerformed
* @param e ActionEvent Event
* @return void
*/
public void actionPerformed(ActionEvent e) {
if(e.getSource()== buttonOk){
if(object!=null){
if(parent == 0){
if(tracer != null){
int length = object.length;
String[] tracers = new String[length];
String[] kits = new String[length];
int[] nums = new int[length];
String[] cname = new String[length];
int[] id =new int[length+1];
int[] wType=new int[length];
for(int i = 0; i < length ; i++) {
String str0 = (String) object[i];
int ind = str0.indexOf("]");
String str1 = str0.substring(1,ind).trim();
nums[i]=winId[idObject[i]];
cname[i]=className[idObject[i]];
id[i]=winId[idObject[i]];
String str2 = str0.substring(ind +1).trim();
tracers[i]=str1;
kits[i]= str2;
wType[i]=radioCode;
try{
window.df.setEntrySelected(tracer.tracerNumber,radioCode,id[i]);
}catch(Exception ex){
window.messageWindow.setErrorMessage( ex );
}
}
tracer.setCheckBox(tracers,kits,cname,nums,wType);
}
}else if(parent == 1){
int length = object.length;
for(int i = 0; i < object.length ; i++) {
String str0 = (String) object[i];
//System.out.println(str0);
int ind = str0.indexOf("]");
String str1 = str0.substring(1,ind).trim();
int subCode =-1;
subCode=winId[idObject[i]];
try{
window.df.setEntrySelected(-1,1,winId[idObject[i]]);
}catch (Exception ex){
window.messageWindow.setErrorMessage( ex );
}
String str2 = str0.substring(ind +1).trim();
str1 = path + ":" + str1;
if(subCode >=0){
Substance substance = new Substance(subCode,str1,str2,window);
//window.vSubstance.addElement(substance);
substance.setVisible(true);
substance.setLocation(150+i*20,100+i*10);
}
}
}else if (parent == 2) {
int length = object.length;
for(int i = 0; i < object.length ; i++) {
String str0 = (String) object[i];
int ind = str0.indexOf("]");
String str1 = str0.substring(1,ind).trim();;
int rctCode =-1;
String cname;
rctCode= winId[idObject[i]];
cname=className[idObject[i]];
try{
window.df.setEntrySelected(-1,2,winId[idObject[i]]);
}catch(Exception ex){
window.messageWindow.setErrorMessage( ex );
}
String str2 = str0.substring(ind +1).trim();
if(rctCode>=0){
Reactor reactor = new Reactor(rctCode,str1,str2,cname,window);
//window.vReactor.addElement(reactor);
reactor.setVisible(true);
reactor.setLocation(150+i*20,100+i*10);
}
}
}
this.setVisible(false);
this.dispose();
}else {
Object message ="No item selected ?";
String title ="EntrySelector";
int messageType = JOptionPane.INFORMATION_MESSAGE;
JOptionPane.showMessageDialog(this.getContentPane(),message,
title,messageType);
}
}
if(e.getSource()== buttonCancel){
this.setVisible(false);
}
}
}
/**
*MyTreeModel Class
* @author XD.Zheng
* @version 1.0
* @since JDK1.2.2
*/
class MyTreeModel
{
/**
* Instance of EntrySelector
*/
EntrySelector entry;
/**
* Constructor
* @param es Instance of EntrySelector
*/
public MyTreeModel(EntrySelector es){
this.entry =es;
}
/**
*EntrySelector Read the tree-structure sentence.
*@param s Tree-structure sentence
*@return TreeModel
*/
public TreeModel getMyTreeModel2(String s){
Vector vModel = new Vector();
Vector vt= new Vector();
DefaultMutableTreeNode root=null;
DefaultMutableTreeNode child;
String currentNode="";
int modeFlag =0;
int kai =0;
int oldkai=0;
try {
StringReader in2 = new StringReader(s);
BufferedReader in3 = new BufferedReader(in2);
while(true) {
String str = in3.readLine();
if(str == null) break;
StringTokenizer st = new StringTokenizer(str,"\t");
String line = st.nextToken();
oldkai=kai;
kai= Integer.parseInt(line);
int size = vt.size();
if(kai!=65536 && kai!=65537){
if((oldkai==65536 ||oldkai==65537) && vModel.size()!=0){
entry.listmode.put(currentNode+oldkai,vModel.clone());
}
if(kai==0){
root= new DefaultMutableTreeNode(st.nextToken());
vt.addElement(root);
}else{
modeFlag =0;
String nt = st.nextToken();
currentNode =nt;
child= new DefaultMutableTreeNode(nt);
((DefaultMutableTreeNode)vt.elementAt(kai-1)).add(child);
if(size<=kai){
vt.addElement(child);
}else{
vt.setElementAt(child,kai);
}
}
}else{
if(oldkai!=kai){
if(vModel.size()!=0){
entry.listmode.put(currentNode+oldkai,vModel.clone());
}
vModel = new Vector();
}
String koumoku = st.nextToken()+"\t["+ st.nextToken() +" ] "+ st.nextToken();
if(st.hasMoreTokens()){
koumoku += "\t" +st.nextToken();
}else{
koumoku += "\t" +"$";
}
vModel.addElement(koumoku);
}
}
if(vModel.size()!=0){
entry.listmode.put(currentNode+kai,vModel.clone());
}
vModel = new Vector();
in3.close();
} catch(java.io.IOException e) {
entry.window.messageWindow.setErrorMessage( e );
}
return new DefaultTreeModel(root);
}
}